package com.chenhao.springcloud.chenhaodatastructureservice.line;

/**
 * Description:线性查找
 *
 * @author chenhao
 * @date 2020/12/2 13:43
 */
public class LinearSearch {
    /**
     *将构造函数定义成private 就是为了外部类不能实例化此类设计
     */
    private LinearSearch(){
    }
    /**
     * 线性查找
     *
     * @param data
     * @param target
     * @return
     */
    public static <E> int search (E[] data, E target){
        for (int i = 0;i< data.length;i++){
            if (data[i].equals(target)){
                return i;
            }
        }
        return -1;
    }

}
